package com.buer.storage.api;


import com.buer.storage.business.domain.ProdCategory;
import com.buer.storage.business.dto.ProdCategoryDto;
import com.buer.storage.business.service.ProdCategoryService;
import com.buer.storage.common.annotation.Auth;
import com.buer.storage.common.eumn.ResultEnum;
import com.buer.storage.common.utils.BaseResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

//装备分类管理
@RestController
@RequestMapping("/prodcategory")
public class ProdCategoryController {
    @Resource
    private ProdCategoryService prodCategoryService;

    //增加装备分类
    @PostMapping("/add.do")
    @Auth
    public BaseResult add(@RequestBody ProdCategoryDto prodCategoryDto) {
        if (prodCategoryService.add(prodCategoryDto) > 0) {
            //添加装备分类成功
            return BaseResult.build(ResultEnum.SUCCESS);
        }
        //添加装备分类失败
        return BaseResult.build(ResultEnum.FAILURE);
    }

    //删除装备分类
    @GetMapping("/delete.do")
    @Auth
    public BaseResult delete(int categoryId) {
        if (prodCategoryService.delete(categoryId) > 0) {
            //删除装备分类成功
            return BaseResult.build(ResultEnum.SUCCESS);
        }
        //删除装备分类失败
        return BaseResult.build(ResultEnum.FAILURE);
    }

    //修改装备分类
    @PostMapping("/update.do")
    @Auth
    public BaseResult update(@RequestBody ProdCategory prodCategory){
        if (prodCategoryService.update(prodCategory)>0){
            //修改装备分类成功
            return BaseResult.build(ResultEnum.SUCCESS);
        }
        //修改装备分类失败
        return BaseResult.build(ResultEnum.FAILURE);
    }

    //查询所有装备分类
    @GetMapping("/select.do")
    @Auth
    public BaseResult select(){
        List<ProdCategory> select = prodCategoryService.select();
        return BaseResult.build(ResultEnum.SUCCESS,select);
    }

    //通过编号或者名字查询
    @GetMapping("/selectByName")
    @Auth
    public BaseResult selectByName(String categoryNumber, String categoryName){
        List<ProdCategory> prodCategories = prodCategoryService.selectByName(categoryNumber,categoryName);
        return BaseResult.build(ResultEnum.SUCCESS,prodCategories);
    }
}
